# # def outer(logo):
# #
# #     def inner(msg):
# #         print(f"<{logo}>{msg}<{logo}>")
# #
# #     return inner
# #
# #
# # f1 = outer("你好")
# # f1("嗯嗯")
# # f1("不好")
# #
# #
# # def outer(num1):
# #
# #     def inner(num2):
# #         nonlocal num1
# #
# #         num1 += num2
# #         print(num1)
# #
# #     return inner
# #
# #
# # result = outer(10)
# # result(20)
# # result(30)
#
# #  ATM 闭包案例
#
# def account_created(initial_account=0):
#
#     def atm(num, deposit=True):
#         nonlocal initial_account
#         if deposit:
#             initial_account += num
#             print(f"存款+{num}元， 当前账户余额{initial_account}")
#         else:
#             initial_account -= num
#             print(f"取款-{num}元， 当前账户余额{initial_account}")
#
#     return atm
#
#
# atm = account_created()
# atm(200)

#  闭包装饰器

# def sleep():
#     import time
#     print("睡眠中.......")
#     time.sleep(5)
#
#
# def outer(func):
#
#     def inner():
#         print("我要睡觉了")
#         func()
#         print("我要起床了")
#
#     return inner
#
#
# h1 = outer(sleep)
# h1()
def outer(func):

    def inner():
        print("我要睡觉了")
        func()
        print("我要起床了")

    return inner


@outer
def sleep():
    import time
    print("睡眠中.......")
    time.sleep(5)


sleep()
